<?php
namespace V1;
class UserPassward extends \ResourceClass
{
    public $isActive = true;
    public $remark = '修改密码';

    /*
     * 参数说明
     * newpassward:新密码,
     * */
    public function post (array $req, array $post, &$result) {
        if (!isset($req['uid'])) {
            return 'require user uid';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }

        $user_cls = \Biz\UserHandler::getById($req['userType'], $req['uid']);
        if (!is_object($user_cls)) {
            return 'data illegal';
        }
        if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'], $user_cls->getEnterpriseId(), $req['t'] . $post['payload'], $req['k']) !== true) {
            return 'data illegal';
        }

        $data = base64_decode($post['payload']);
        @parse_str($data,$data);

        if(!array_key_exists('newpassward',$data)){
            return 'require newpassward info';
        }
        $password = md5($data['newpassward']);
        $user_cls->setPassword($password);
        if (\Biz\UserHandler::update($req['userType'], $user_cls) !== true) {
            return '更新失败';
        }
        return '';
    }
}